package com.shenmazong.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @program: server-java-demo
 * @description: CallableDemo1
 * @author: 亮子说编程
 * @create: 2020-11-13 10:15
 **/


class ThreadCallable implements Callable<Integer> {
    public Integer call() throws Exception {
        for (int i = 0; i < 20; i++) {
            System.out.println(Thread.currentThread().getName()+",i="+i);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        return 0;
    }
}

public class CallableDemo1 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //-- FutureTask -> RunnableFuture -> Runnable
        FutureTask<Integer> task = new FutureTask<>(new ThreadCallable());
        new Thread(task, "aaa").start();

        System.out.println(task.get());
    }
}